package behavior.mediator;

import java.util.HashMap;
import java.util.Map;

public class ConcreteMediator implements Mediator {
    Map<String,Colleague> map = new HashMap<String,Colleague>();
    Map<String,String> interMap = new HashMap<String,String>();


    @Override
    public void getMessage(int status, String name) {
        Colleague colleague = map.get(name);
        if(colleague instanceof Alarm){
            String key = interMap.get("TV");
            TV tv = (TV) map.get(key);

            if(status==1){
                tv.on();
            }else if(status==0){
                tv.off();
            }
        }
    }

    @Override
    public void register(String name, Colleague colleague) {
        map.put(name,colleague);
        if(colleague instanceof Alarm){
            interMap.put("Alarm", name);
        }else if(colleague instanceof TV){
            interMap.put("TV", name);
        }
    }
}
